class MyPromise{
    constructor(fn){
        this.status = 'pending';//状态
        this.value = '';//数据
        this.error = '';//错误的信息
        let resolve = (data) => {
            this.status = 'fulfilled';//成功
            this.value = data;
        }
        
        let reject = (error) => {
            this.status = 'rejected';//失败
            this.error = error;
        }
        fn(resolve,reject);
    }
    then(success,reject){//then方法
        if(this.status === 'fulfilled'){
            success(this.value);//成功执行的函数
        }else if(this.status === 'rejected'){
            reject(this.error);//失败执行的函数
        }
    }
}

new MyPromise((resolve,reject) => {//myPromise的实例
    reject('error');
}).then(res => {//成功
    console.log(res);
},error => { //失败
    console.log("error",error);
})